cd "/Users/alee87/Dropbox/Agra/"
use "./Analysis/vill81_sett_oct2004.dta", clear

do "./Analysis/genindex1.do"

genindex  pprimary81  ppost81 pmiddle81  panypower81 pproad81   ,nv(pg_index)

label var pprimary81 "Primary School"
label var pmiddle81 "Middle School"
label var phigh81 "High School"
label var panypower81 "Electricity"
label var pproad81 "Pucca Road"
label var ppost81 "Post Office"
label var pg_indexA  "Public Goods Index"
label var p_nland "Non-Landlord Tenure"

encode state, gen(statenum)

*land table A18
*no fe ryot
foreach var of varlist pprimary81 {
quietly reg `var'   p_nland  
outreg2 using  "./Tables/bi_ryot.tex", keep( p_nland )  addtext( State FE, NO)  label replace   nocons


 }

 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'    p_nland  if pprimary81!=.
outreg2 using  "./Tables/bi_ryot.tex", keep( p_nland )  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 
*no fe
foreach var of varlist pprimary81 {
quietly reg `var'   p_nland  if tenure!="Raiyatwari" & tenure!="Mixed"
outreg2 using  "./Tables/bi_noryot.tex", keep( p_nland )  addtext( State FE, NO)  label replace   nocons


 }

 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'    p_nland  if tenure!="Raiyatwari"& tenure!="Mixed" &pprimary81!=.
outreg2 using  "./Tables/bi_noryot.tex", keep( p_nland )  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 
 * fe
foreach var of varlist pprimary81 {
quietly reg `var'   p_nland i.statenum if tenure!="Raiyatwari"& tenure!="Mixed"
outreg2 using  "./Tables/bi_fe.tex", keep( p_nland )  addtext( State FE, YES)  label replace   nocons


 }

 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'    p_nland i.statenum if tenure!="Raiyatwari"& tenure!="Mixed"  &pprimary81!=.
outreg2 using  "./Tables/bi_fe.tex", keep( p_nland )  addtext(State FE, YES)  label append tex(frag)   nocons


 }
 
  * up
foreach var of varlist pprimary81 {
quietly reg `var'   p_nland if state=="Uttar Pradesh"
outreg2 using  "./Tables/bi_up.tex", keep( p_nland )  addtext( State FE, NO)  label replace   nocons


 }

 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'    p_nland i.statenum if state=="Uttar Pradesh" &pprimary81!=.
outreg2 using  "./Tables/bi_up.tex", keep( p_nland )  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 

quietly reg  pg_indexA    p_nland  if pprimary81!=.
est store est_bi_ryot


quietly reg pg_indexA    p_nland  if tenure!="Raiyatwari"& tenure!="Mixed" &pprimary81!=.
est store est_bi_nofe

quietly reg pg_indexA    p_nland i.statenum if tenure!="Raiyatwari"& tenure!="Mixed"  &pprimary81!=.
est store est_bi_fe

quietly reg pg_indexA p_nland i.statenum if state=="Uttar Pradesh" &pprimary81!=.
est store est_bi_up
 
 coefplot (est*), keep(p_nland) xline(0) asequation swapnames   coeflabels(est_bi_ryot="All India" est_bi_nofe ="No Ryotwari"  est_bi_fe="No Ryotwari, State FE" est_bi_up="Within Uttar Pradesh")
   graph2tex, epsfile("./Paper/bi_pg_models")
  estimates clear
  
  *Table A19 caste
  clear
 use  "./Analysis/BIwithcaste"
 
 do "./Analysis/genindex1.do"
 
 genindex  pprimary81  ppost81 pmiddle81  panypower81 pproad81   ,nv(pg_index)

label var pprimary81 "Primary School"
label var pmiddle81 "Middle School"
label var phigh81 "High School"
label var panypower81 "Electricity"
label var pproad81 "Pucca Road"
label var ppost81 "Post Office"
label var pg_indexA  "Public Goods Index"
label var p_nland "Non-Landlord Tenure"

encode state, gen(statenum)
 
 replace uppervarna=.
  replace uppervarna=dn6
 label var uppervarna "Prop. Upper Caste"
  label var  uppervarna_broad  "Prop. Upper Caste"
 
 *no fe
foreach var of varlist pprimary81 {
quietly reg `var'   uppervarna 
outreg2 using  "./Tables/bi_caste_nofe.tex", keep( uppervarna )  addtext( State FE, NO)  label replace   nocons


 }
 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'   uppervarna  if  pprimary81!=.
outreg2 using  "./Tables/bi_caste_nofe.tex", keep( uppervarna)  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 
  * fe
foreach var of varlist pprimary81 {
quietly reg `var'   uppervarna i.statenum 
outreg2 using  "./Tables/bi_caste_fe.tex", keep( uppervarna)  addtext( State FE, YES)  label replace   nocons


 }

 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'   uppervarna i.statenum if   pprimary81!=.
outreg2 using  "./Tables/bi_caste_fe.tex", keep( uppervarna )  addtext(State FE, YES)  label append tex(frag)   nocons


 }
 
  * up
foreach var of varlist pprimary81 {
quietly reg `var'   uppervarna if state=="Uttar Pradesh"
outreg2 using  "./Tables/bi_caste_up.tex", keep( uppervarna )  addtext( State FE, NO)  label replace   nocons


 }

 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'   uppervarna i.statenum if state=="Uttar Pradesh" &pprimary81!=.
outreg2 using  "./Tables/bi_caste_up.tex", keep( uppervarna )  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 
  *altdef
  foreach var of varlist pprimary81 {
quietly reg `var'   uppervarna_broad 
outreg2 using  "./Tables/bi_caste_bigdef.tex", keep( uppervarna_broad )  addtext( State FE, NO)  label replace   nocons


 }
 
foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'   uppervarna_broad  if  pprimary81!=.
outreg2 using  "./Tables/bi_caste_bigdef.tex", keep( uppervarna_broad)  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 
 
foreach var of varlist pprimary81 {
quietly reg `var'   uppervarna_broad  i.statenum 
outreg2 using  "./Tables/bi_caste_bigdef_fe.tex", keep( uppervarna_broad )  addtext( State FE, YES)  label replace   nocons


 }
 

foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'   uppervarna_broad i.statenum  if  pprimary81!=.
outreg2 using  "./Tables/bi_caste_bigdef_fe.tex", keep( uppervarna_broad)  addtext(State FE, YES)  label append tex(frag)   nocons


 }
 
 foreach var of varlist pprimary81 {
quietly reg `var'   uppervarna_broad  if state=="Uttar Pradesh" 
outreg2 using  "./Tables/bi_caste_bigdef_up.tex", keep( uppervarna_broad )  addtext( State FE, NO)  label replace   nocons


 }


 foreach var of varlist  ppost81 pmiddle81  panypower81 pproad81  pg_indexA {
quietly reg `var'   uppervarna_broad  if state=="Uttar Pradesh" & pprimary81!=.
outreg2 using  "./Tables/bi_caste_bigdef_up.tex", keep( uppervarna_broad)  addtext(State FE, NO)  label append tex(frag)   nocons


 }
 
 




 

 
 quietly reg  pg_indexA    uppervarna  if pprimary81!=.
est store est_bi_nofe

rename uppervarna temp
rename uppervarna_broad uppervarna
 quietly reg  pg_indexA    uppervarna  if pprimary81!=.
*est store est_bi_bigdef
rename uppervarna uppervarna_broad 
rename temp uppervarna

quietly reg pg_indexA    uppervarna  i.statenum if pprimary81!=.
est store est_bi_fe

quietly reg pg_indexA  uppervarna  i.statenum if state=="Uttar Pradesh" &pprimary81!=.
est store est_bi_up
 
 coefplot (est*), keep(uppervarna ) xline(0) asequation swapnames   coeflabels( est_bi_nofe ="All India"  est_bi_fe="State FE" est_bi_up="Within Uttar Pradesh")
   graph2tex, epsfile("./Paper/bi_caste_pg_models")
  estimates clear

